package com.bkhech.bigdata.tiktok_anchor.videoinfotop10;

import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

/**
 * 日期工具类
 *
 * @author guowm
 * @date 2022/7/6
 */
public class DateUtils {

    /**
     * 转换日期格式
     * 从yyyyMMdd转换为yyyy-MM-dd
     *
     * @param dt
     * @return
     */
    public static String transDataFormat(String dt) {
        String res = "1970-01-01";
        try {
            TemporalAccessor accessor = DateTimeFormatter.ofPattern("yyyyMMdd").parse(dt);
            res = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(accessor);
        } catch (Exception e) {
            System.out.println("日期转换失败：" + dt);
        }
        return res;
    }
}
